package com.baicaoyuan.web.common;

import java.sql.Timestamp;

/**
 * 功能描述：
 *
 * @author 罗富祥
 * 创建时间： 2018/1/5
 */
public class TimeUtils {

    /**
     * 获取当前时间
     *
     * @return
     */
    public static Timestamp getCurrentTime() {
        return new Timestamp(System.currentTimeMillis());
    }

    public static boolean checkOvertimeNow(Timestamp timestamp, Integer minutes) {
        long c = timestamp.getTime() + (minutes * 60 * 1000);
        long now = getCurrentTime().getTime();
        return now > c;
    }

    public static Timestamp getMinTime(String date) {

        if (StringUtils.isNullOrEmpty(date)) {
            return null;
        }

        StringBuilder builder = new StringBuilder();
        builder.append(date);
        builder.append(" 00:00:00");

        return Timestamp.valueOf(builder.toString());
    }

    public static Timestamp getMaxTime(String date) {

        if (StringUtils.isNullOrEmpty(date)) {
            return null;
        }

        StringBuilder builder = new StringBuilder();
        builder.append(date);
        builder.append(" 23:59:59");

        return Timestamp.valueOf(builder.toString());
    }

    public static long days(Timestamp begin, Timestamp end) {
        return (end.getTime() - begin.getTime()) / 1000 / 60 / 60 / 24 + 1;
    }

}
